#ifndef BORDLAYOUT_H_
#define BORDLAYOUT_H_

#include <QLayout>
#include <QMap>
#include <HexVector.h>
#include "BordPixmap.h"
#include "../util/BijectionMap.h"

using namespace structure;

class ElementButton;
class HexagonButton;

class BordLayout : public QLayout
{
	Q_OBJECT

public:
	// constructor & destructor
	BordLayout(QWidget * parent = 0);
	virtual ~BordLayout();

	// element functions
	ElementButton * getElementAt(const HexVector & position);
	void removeElementAt(const HexVector & position);

	// layout change functions
	int setHexagonRadius(int proposedRadius);

	// overloaded functions
	QSize sizeHint() const;
	QSize minimumSize() const;
	QSize maximumSize() const;
	void addItem(QLayoutItem * item);
	void setGeometry(const QRect & rct);
	QLayoutItem* itemAt(int i) const;
	QLayoutItem* takeAt(int i);
	int count() const;


private:
	void calculateSize();
	void setElementLayoutData(ElementButton * button);
	void setHexagonLayoutData(HexagonButton * button);
	void setElementsLayoutData();
	QRect calculateHexagonGeometry(const QRect & rect, const HexVector & position) const;
	QRect calculateCornerGeometry(const QRect & rect, const HexVector & position) const;
	QRect calculateSideGeometry(const QRect & rect, const HexVector & position) const;

	QList<QLayoutItem *> arNormalItems, arHexagonItems, arCornerItems, arSideItems;
	BijectionMap<HexVector, QLayoutItem *> arElementItems;

	QSize centerSize;

	struct LayoutData
	{
	public:
		QSize gridSize;
		QSize hexagonSize;
		QPolygon hexagonPolygon;
		QSize cornerSize;
		QRect cornerRect;
		QSize sideSize[3];
		QPolygon sidePolygon[3];
	};
	LayoutData layoutData;
	BordPixmap bordPixmap;
};

#endif /* BORDLAYOUT_H_ */
